{include file="public/header" /}
<body>
<div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-body">
                <blockquote class="layui-elem-quote">
                    请上传xls、xlsx格式文件
                </blockquote>
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-primary" id="chooseFile">选择文件</button><br>
                    <button type="button" class="layui-btn layui-btn-normal" id="uploadFile"><i class="layui-icon"></i>开始上传</button>
                </div>
                <div class="download-template">
                    <a href="javascript:;" onclick="downloadTemplate()">下载模板</a>
                </div>
            </div>
        </div>
    </div>
</div>
<style>
    #uploadFile{
        margin-top: 10px;
    }
</style>
</body>
<script>
    layui.use(['upload', 'element', 'layer'], function(){
        var $ = layui.jquery
            ,upload = layui.upload
            ,element = layui.element
            ,layer = layui.layer;

        //选完文件后不自动上传
        upload.render({
            elem: '#chooseFile',
            url: "{:url('user/import')}",
            auto: false,
            // multiple: true,//是否自动上传
            bindAction: '#uploadFile',
            accept:'file',
            exts:'xls|xlsx',
            done: function(res){
                if (res.code == 'suc') {
                    sucMsg(res.msg,function () {
                        parent.layui.table.reload('userList')
                        xadmin.close();
                    })
                }else {
                    errMsg(res.msg)
                }
            },
            error:function (err) {
                errMsg('系统繁忙，请重试',function () {
                    xadmin.reload()
                })
            }
        });
    })

    function downloadTemplate() {
        location.href = "{:url('user/downloadTemplate')}"
    }
</script>
</html>